﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace API.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class UploadController : ControllerBase
    {
        public UploadController(IWebHostEnvironment web)
        {
            Web = web;
        }

        public IWebHostEnvironment Web { get; }

        [HttpPost]
        public IActionResult upload(IFormFile file)
        {
            //取wwwroot文件夹的物理路径
            string path = Web.WebRootPath + @"\pic\";
            //上传三行代码
            FileStream fs = System.IO.File.Create(path + file.FileName);
            file.CopyTo(fs);
            fs.Close();
            //返回虚拟路径
            return Ok("/pic/" + file.FileName);
        }
    }
}
